# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: eolianoe <eolianoe At GoogleMAIL DoT com>
# Contributor: Étienne Deparis <etienne [at] depar.is>
# Contributor: Patrice Peterson <runiq at archlinux dot us>
# Contributor: Patrick Burroughs <celticmadman at gmail dot com>

_name=tzlocal
pkgname=python-tzlocal
pkgver=4.3
pkgrel=3
epoch=1
pkgdesc="Tzinfo object for the local timezone"
arch=('any')
url="https://github.com/regebro/tzlocal"
license=('MIT')
depends=('python-pytz-deprecation-shim')
makedepends=('python-build' 'python-installer' 'python-setuptools'
             'python-wheel')
checkdepends=('python-pytest' 'python-pytest-mock')
source=("https://files.pythonhosted.org/packages/source/${_name::1}/${_name}/${_name}-${pkgver}.tar.gz")
sha256sums=('3f21d09e1b2aa9f2dacca12da240ca37de3ba5237a93addfd6d593afe9073355')
b2sums=('a1b7ffe943fff5e0042e0e6e3ac4c53b8724b0a3142a67b4621441735e65e645710e15276bc074e178268a1663e6c6aae2ae6b889b5a820df3edf3292cf919f9')

prepare() {
  mv -v "${_name}-${pkgver}" "${pkgname}-${pkgver}"
  cd "${pkgname}-${pkgver}"
  # fix symlink, required for test: https://github.com/regebro/tzlocal/issues/53
  cd tests/test_data/symlink_localtime/etc
  ln -sfv ../usr/share/zoneinfo/Africa/Harare localtime
}

build() {
  cd "${pkgname}-${pkgver}"
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${pkgname}-${pkgver}"
  export PYTHONPATH="build:${PYTHONPATH}"
  pytest -v -k 'not test_conflicting and not test_noconflict'
}

package() {
  cd "${pkgname}-${pkgver}"
  python -m installer --destdir="${pkgdir}" dist/*.whl
  # docs
  install -vDm 644 {CHANGES.txt,README.rst} \
    -t "${pkgdir}/usr/share/doc/${pkgname}"

  # symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "${pkgdir}"/usr/share/licenses/${pkgname}
  ln -s "${site_packages}"/${_name}-${pkgver}.dist-info/LICENSE.txt \
    "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE.txt
}

# vim:set ts=2 sw=2 et:
